<template>
	<div style="height:100%">
		<cl-crud @load="onLoad">
			<template #table-column-iconUrl="{scope}">
				<cl-avatar
					shape="square"
					size="medium"
					:src="scope.row.iconUrl | default_avatar"
					:style="{ margin: 'auto' }"
				>
				</cl-avatar>
			</template>
			<template #table-column-type="{scope}">
				<el-tag v-if="scope.row.type == 1" type="success">是</el-tag>
				<el-tag type="info" v-else>否</el-tag>
			</template>
			<template #table-column-status="{scope}">
				<el-tag v-if="scope.row.status == 1" type="success">启用</el-tag>
				<el-tag type="info" v-else>禁用</el-tag>
			</template>
		</cl-crud>
	</div>
</template>

<script>
export default {
	data() {
		return {};
	},

	mounted() {},

	methods: {
		onLoad({ ctx, app }) {
			this.crud = app;
			ctx.service(this.$service.integralMall.redPacket)
				.set('table', {
					columns: [
						{
							prop: 'startTime',
							label: '开抢时间',
							align: 'center',
							sortable: 'custom'
						},

						{
							prop: 'amount',
							label: '个数',
							align: 'center',
							sortable: 'custom'
						},

						{
							prop: 'goldAmount',
							label: '金币数',
							align: 'center',
							sortable: 'custom'
						},

						{
							prop: 'status',
							label: '状态',
							align: 'center'
						}
					],
					op: {
						layout: ['edit', 'delete']
					}
				})
				.set('upsert', {
					props: {
						labelWidth: '112px'
					},
					items: [
						{
							prop: 'startTime',
							label: '开抢时间(点)',
							component: {
								name: 'el-time-picker',
								props: {
									format: 'HH:mm',
									'value-format': 'HH:mm'
								}
							},
							rules: [
								{
									required: true,
									message: '请选择开抢时间',
									trigger: 'blur'
								}
							]
						},
						{
							prop: 'amount',
							label: '个数(个)',
							value: 1,
							component: {
								name: 'el-input-number',
								attrs: {
									min: 1
								}
							},
							rules: [
								{
									required: true,
									message: '请输入红包个数',
									trigger: 'blur'
								}
							]
						},
						{
							prop: 'goldAmount',
							label: '金币数(金币)',
							value: 1,
							component: {
								name: 'el-input-number',
								attrs: {
									min: 1
								}
							},
							rules: [
								{
									required: true,
									message: '请输入金币数',
									trigger: 'blur'
								}
							]
						},
						{
							prop: 'sceneKey',
							label: '场景值',
							component: {
								name: 'el-input',
								attrs: {
									size: 'mini',
									disabled: false
								}
							},
							rules: [
								{
									required: true,
									message: '请输入场景值',
									trigger: 'blur'
								}
							]
						},
						{
							prop: 'status',
							label: '状态',
							value: 1,
							component: {
								name: 'el-radio-group',

								options: [
									{
										label: '启用',
										value: 1
									},
									{
										label: '禁用',
										value: 2
									}
								]
							}
						}
					]
				})
				.set('layout', [
					['refresh-btn', 'add-btn'],
					['data-table'],
					['flex1', 'pagination']
				])
				.on('open', async (isEdit, data) => {
					if (isEdit) {
						app.setData('upsert.items[prop:sceneKey].component.attrs.disabled', true);
					} else {
						app.setData('upsert.items[prop:sceneKey].component.attrs.disabled', false);
					}
				})
				.on('submit', async (isEdit, data, { next }) => {
					next({
						...data
					});
				})
				.done();
			app.refresh();
		}
	}
};
</script>
<style lang="scss" scoped></style>
